package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.annotation.DisableLoginCheck;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.OrderSupplier;
import com.zoshine.zzg.pojo.OrderSupplierDetail;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.OrderSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * 供应商订单Controller
 * @author 田沛凌
 * @time 2017年6月26日 下午4:03:40
 */
@RestController
@RequestMapping(value="orderSupplier", method = RequestMethod.POST)
public class OrderSupplierController extends BaseController{

	private OrderSupplierService orderSupplierService;
	
	@Autowired
	public void setOrderSupplierService(OrderSupplierService orderSupplierService) {
		this.orderSupplierService = orderSupplierService;
	}
	/**
	 * 获取单个供应商订单
	 * @param id 供应商订单ID
	 * @return 供应商订单
	 */
	@RequestMapping("/getOrderSupplier")
	public BaseResponse getOrderSupplier(Long id){
		OrderSupplier orderSupplier = orderSupplierService.get(id);
		return new AppResponse(orderSupplier);
	}
	/**
	 * 供应商订单分页查询
	 * @param orderSupplier;
	 * @return 订单集合
	 */
	@RequestMapping("/pageOrderSupplier")
	public BaseResponse pageListOrderSupplier(OrderSupplier orderSupplier){
		List<Long> prisonsList= super.getPrisonPower();
		List<Long> supplierList= super.getSupplierPower();
		orderSupplier.setPrisonPower(prisonsList);
		orderSupplier.setSupplierPower(supplierList);
		List<OrderSupplier> pageList = orderSupplierService.list(orderSupplier);
		return new AppResponse(new PageInfo<>(pageList));
	}
	/***
	 * 新增供应商订单
	 */
	@RequestMapping("/addOrderSupplier")
	public BaseResponse addOrderSupplier(HttpSession session){
		orderSupplierService.addOrderSupplier(session);
		return AppResponse.OK;
	}
	/**
	 * 修改供应商订单
	 * @param orderSupplier；
	 */
	@RequestMapping("/editOrderSupplier")
	public BaseResponse editOrderSupplier(OrderSupplier orderSupplier){
		 orderSupplierService.edit(orderSupplier);
		return AppResponse.OK;
	}
	/**
	 * 删除供应商订单
	 * @param id 供应商订单ID
	 */
	@RequestMapping("/delOrderSupplier")
	public BaseResponse delOrderSupplier(Long id){
		orderSupplierService.delOrderSupplier(id);
		return AppResponse.OK;
	}
	/**
	 * 供应商订单详情查看
	 * @param id (供应商订单)
	 * @return 详情查询
	 */
	@RequestMapping("/pageDetailList")
	public BaseResponse pageDetailList(Long id){
		List<OrderSupplierDetail> listOrderSupplierDetail = orderSupplierService.ListOrderSupplierDetail(id);
		return new AppResponse(listOrderSupplierDetail);
	}
}
